import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2023-11-04
 * Time: 17:55
 */
public class Test {

    //汉诺塔问题:
    /*
        pos1:起始位置
        pos2:中转位置
        pos3:结束位置
     */

    //用于表示汉诺塔的移动逻辑:
    public static void hanoi(int n, char pos1, char pos2, char pos3) {
        if(n == 1) {
           move(pos1,pos3);
        }else {
            hanoi(n-1,pos1,pos3,pos2);
            move(pos1,pos3);
            hanoi(n-1,pos2,pos1,pos3);
        }
    }
    public static void move(char pos1, char pos2) {
        System.out.println(pos1 + "->" + pos2);
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入汉诺塔的盘数:");
        int n = scanner.nextInt();
        hanoi(n,'a','b','c');
        scanner.close();
    }

//    public static void hanoi(int n, char pos1, char pos2,char pos3) {
//        if(n == 1) {
//            move(pos1,pos3);
//        }else {
//            hanoi(n-1,pos1,pos3,pos2);
//            move(pos1,pos3);
//            hanoi(n-1,pos2,pos1,pos3);
//        }
//    }
//    //利用move方法来表示移动
//    public static void move(char pos1 ,char pos2) {
//        System.out.println(pos1 + "->" + pos2);
//    }
//    public static void main(String[] args) {
//        hanoi(5,'A','B','C');
//    }






    //递归求斐波那契数列的第 N 项
    public static int fib(int n) {
        if(n == 1 || n ==2) {
            return 1;
        }else {
            return fib(n-1) + fib(n-2);
        }
    }
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ret = fib(n);
        System.out.println(ret);
        scanner.close();
    }


    //写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static int sum(int n) {
        if(n < 10) {
            return n;
        }else {
            return sum(n / 10) * (n % 10);
        }
    }
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int ret = sum(num);
        System.out.println(ret);
        scanner.close();
    }
//
//    public static int sum(int x) {
//        if(x == 1) {
//            return 1;
//        }else {
//            return x+sum(x-1);
//        }
//    }
//    public static void main3(String[] args) {
//        int ret = sum(10);
//        System.out.println(ret);
//    }


    //利用递归顺序按位打印整数每一位的信息
    public static void prt(int a) {
        if(a < 10) {
            System.out.print(a+" ");
        }else {
            prt(a / 10);
            System.out.print(a % 10 + " ");
        }
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        prt(num);
    }


    //阶乘
    public static int fac(int a) {
        if(a == 1) {
            return 1;
        }else {
            return a*fac(a-1);
        }
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int ret = fac(n);
        System.out.println(ret);
    }
}
